$: << File.join(File.expand_path(File.dirname(__FILE__)), "..")

require 'rubygems'
require 'mapper/ColExtractor'
require 'mapper/Normalizer'
require 'mapper/Filter'
require 'test/unit'

class MapperTest < Test::Unit::TestCase
	@@file = "test.data"
	def test_extractor_no_ignore
		cls = ColExtractor.new('--key 1 --value 3 --no-ignore')
		counter = 0
		assert_raise(Exception){
			file = File.new(@@file,"r")
			while(line=file.gets)
				output = cls.execute(line)
				counter = counter + 1 if output
			end
		}
	end
	
	def test_extractor
		cls = ColExtractor.new('--key 0 --value 3')
		counter = 0
		file = File.new(@@file,"r")
		while(line=file.gets)
			output = cls.execute(line)
			counter = counter + 1 if output
		end
		assert_equal(29, counter)
	end
	
	def test_filter_no_ignore
		cls = Filter.new('--field 3:iszero --no-ignore')
		counter = 0
		assert_raise(Exception){
			file = File.new(@@file,"r")
			while(line=file.gets)
				output = cls.execute(line)
				counter = counter + 1 if output
			end
		}		
	end
	
	def test_filter2
		cls = Filter.new('--field 3:iszero')
		counter = 0
		file = File.new(@@file,"r")
		while(line=file.gets)
			output = cls.execute(line)
			counter = counter + 1 if output
		end
		assert_equal(28, counter)
	end
end

